prep_data <- function(x){
  x$var <- rownames(x) 
  x <- rename.vars(x, from="Estimate", to="pe")
  x <- rename.vars(x, from="Std. Error", to="se")
  x$ul <- x$pe + 1.96*x$se 
  x$ll <- x$pe - 1.96*x$se 
  x$var[x$var=="threat_britain"] <- "   argued that a politician constitutes a threat"
  x$var[x$var=="court_crisis"] <- "   argued that the government may ignore courts"
  x$var[x$var=="no_parliament"] <- "   argued that the government may rule without consulting Parliament "
  x$var[x$var=="exclude_journalists"] <- "   argued that the government should exclude journalists"
  x$var[x$var=="expenses"] <- "   claimed GBP 20,000 as parliamentary expenses"
  x$var[x$var=="online_harrasment"] <- "   encouraged online harassment"
  x$var[x$var=="ignored_messages"] <- "   ignored multiple messages"
  x$var[x$var=="actor_same_party"] <- "   MPs from the candidate's own party"
  x$var[x$var=="expelled"] <- "   called for the candidate to be expelled"
  x$var[x$var=="criticized"] <- "   criticized the behavior"
  x$var[x$var=="defended"] <- "   defended the behavior"
  x$var[x$var=="refused_work"] <- "   refused to work with the candidate"
  x$var[x$var=="female"] <- "   female"
  x$var[x$var=="minister"] <- "   minister"
  x$var[x$var=="conservative"] <- "   Conservative"
  x <- subset(x, select=c("var", "pe", "se", "ul", "ll"))
  x <- rbind(a, x[2:8,], b, x[9,], c, x[10:13,], d, x[14,], e, x[15,], f, x[16,])
  x$pe <- as.numeric(x$pe)
  x$se <- as.numeric(x$se)
  x$ll <- as.numeric(x$ll)
  x$ul <- as.numeric(x$ul)
  return(x)
  }

prep_data2 <- function(x){
  x <- rename.vars(x, from="estimate", to="pe")
  x$level <- as.character(x$level)
  x <- rename.vars(x, from="level", to="var") 
  x <- rename.vars(x, from="std.error", to="se")
  x <- rename.vars(x, from="lower", to="ll")
  x <- rename.vars(x, from="upper", to="ul") 
  x$rank[x$var=="Had an extramarital affair"] <- 1
  x$rank[x$var=="Argued that a politician constitutes a threat"] <- 2
  x$rank[x$var=="Argued that the government may ignore courts"] <- 3
  x$rank[x$var=="Argued that the government may rule without consulting Parliament"] <- 4
  x$rank[x$var=="Argued that the government should exclude journalists"] <- 5
  x$rank[x$var=="Encouraged online harassment"] <- 6
  x$rank[x$var=="Claimed GBP 20,000 as parliamentary expenses"] <- 7 
  x$rank[x$var=="Ignored multiple messages"] <- 8
  x$rank[x$var=="MPs from another party"] <- 9
  x$rank[x$var=="MPs from the candidate's own party"] <- 10
  x$rank[x$var=="did not react"] <- 11
  x$rank[x$var=="called for the candidate to be expelled"] <- 12
  x$rank[x$var=="criticized the behavior"] <- 13
  x$rank[x$var=="defended the behavior"] <- 14
  x$rank[x$var=="refused to work with the candidate"] <- 15
  x$rank[x$var=="Male"] <- 16
  x$rank[x$var=="Female"] <- 17
  x$rank[x$var=="Labour"] <- 18  
  x$rank[x$var=="Conservative"] <- 19
  x$rank[x$var=="No"] <- 20
  x$rank[x$var=="Yes"] <- 21
  x$rank <- as.numeric(x$rank)
  x <- x[order(x$rank),]
  x$var[x$var=="Male"] <- "   male"
  x$var[x$var=="Female"] <- "   female"
  x$var[x$var=="No"] <- "   no minister"
  x$var[x$var=="Yes"] <- "   minister"
  x$var[x$var=="Conservative"] <- "   Conservative"
  x$var[x$var=="Labour"] <- "   Labour"
  x$var[x$var=="Had an extramarital affair"] <- "   had an extramarital affair"
  x$var[x$var=="Argued that a politician constitutes a threat"] <- "   argued that a politician constitutes a threat"
  x$var[x$var=="Argued that the government may ignore courts"] <- "   argued that the government may ignore courts"
  x$var[x$var=="Argued that the government may rule without consulting Parliament"] <- "   argued that the government may rule without consulting Parliament "
  x$var[x$var=="Argued that the government should exclude journalists"] <- "   argued that the government should exclude journalists"
  x$var[x$var=="Claimed GBP 20,000 as parliamentary expenses"] <- "   claimed GBP 20,000 as parliamentary expenses"
  x$var[x$var=="Encouraged online harassment"] <- "   encouraged online harassment"
  x$var[x$var=="Ignored multiple messages"] <- "   ignored multiple messages"
  x$var[x$var=="MPs from the candidate's own party"] <- "   MPs from the candidate's own party"
  x$var[x$var=="MPs from another party"] <- "   MPs from another party"
  x$var[x$var=="did not react"] <- "   did not react"
  x$var[x$var=="called for the candidate to be expelled"] <- "   called for the candidate to be expelled"
  x$var[x$var=="criticized the behavior"] <- "   criticized the behavior"
  x$var[x$var=="defended the behavior"] <- "   defended the behavior"
  x$var[x$var=="refused to work with the candidate"] <- "   refused to work with the candidate"
  x <- subset(x, select=c("var", "pe", "se", "ul", "ll"))
  x <- rbind(a, x[1:8,], b, x[9:10,], c, x[11:15,], d, x[16:17,], e, x[18:19,], f, x[20:21,])
  x$pe <- as.numeric(x$pe) 
  x$se <- as.numeric(x$se)
  x$ll <- as.numeric(x$ll)
  x$ul <- as.numeric(x$ul)
  return(x)
  }